package com.pshcp.doctor.tool;

import com.framework.base.BaseDTO;
import com.framework.thread.ReqComTool;
import com.framework.tool.CommonTool;
import com.pshcp.doctor.ao.patient.DoctorPatientAuditPageAO;
import com.pshcp.doctor.ao.patient.DoctorPatientPoolPageAO;
import com.pshcp.doctor.vo.patient.DoctorArticlePatientVO;
import com.pshcp.domain.dto.DoctorPatientDTO;
import com.pshcp.domain.model.DoctorArticleNotificationPatient;
import com.pshcp.domain.model.DoctorPatient;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: TODO
 * @Author: xiaoche
 * @Date: 2022/11/4 01:35
 */
public class DoctorPatientTool {

    public static DoctorPatientDTO buildGetDoctorPatientPoolPage(DoctorPatientPoolPageAO doctorPatientPoolPageAO) {
        BaseDTO baseDTO = CommonTool.buildBaseDTO(doctorPatientPoolPageAO.getPageNum(), doctorPatientPoolPageAO.getPageSize());
        DoctorPatientDTO doctorArticleDTO = new DoctorPatientDTO();
        doctorArticleDTO.setPageNum(baseDTO.getPageNum());
        doctorArticleDTO.setPageSize(baseDTO.getPageSize());
        doctorArticleDTO.setSearch(doctorPatientPoolPageAO.getSearch());
        doctorArticleDTO.setDoctorId(ReqComTool.getUserId());
        doctorArticleDTO.setSearchType(0);
        doctorArticleDTO.setSearch(doctorPatientPoolPageAO.getSearch());
        doctorArticleDTO.setType(doctorPatientPoolPageAO.getType());
        doctorArticleDTO.setRelationFlag(doctorPatientPoolPageAO.getRelationFlag());
        return doctorArticleDTO;
    }

    public static DoctorPatientDTO buildGetDoctorPatientAuditPage(DoctorPatientAuditPageAO DoctorPatientAuditPageAO) {
        BaseDTO baseDTO = CommonTool.buildBaseDTO(DoctorPatientAuditPageAO.getPageNum(), DoctorPatientAuditPageAO.getPageSize());
        DoctorPatientDTO doctorArticleDTO = new DoctorPatientDTO();
        doctorArticleDTO.setPageNum(baseDTO.getPageNum());
        doctorArticleDTO.setPageSize(baseDTO.getPageSize());
        doctorArticleDTO.setDoctorId(ReqComTool.getUserId());
        doctorArticleDTO.setAuditStatus(0);
        return doctorArticleDTO;
    }

    public static DoctorPatient buildAuditDoctorPatient(DoctorPatient doctorPatient) {
        doctorPatient.setRelationFlag(1);
        doctorPatient.setAuditStatus(1);
        return doctorPatient;
    }

    public static DoctorPatient buildSaveDoctorPatientRemark(DoctorPatient doctorPatient,String remark) {
        doctorPatient.setRemark(remark);
        return doctorPatient;
    }

    public static DoctorPatient buildRemoveDoctorPatient(DoctorPatient doctorPatient) {
        doctorPatient.setRelationFlag(0);
        doctorPatient.setAuditStatus(0);
        return doctorPatient;
    }

    public static List<DoctorArticlePatientVO> buildGetDoctorArticlePatientList(List<DoctorPatient> doctorPatientList, List<DoctorArticleNotificationPatient> doctorArticleNotificationPatientList) {
        Map<Long, DoctorArticleNotificationPatient> doctorArticleNotificationPatientMap = doctorArticleNotificationPatientList.stream().collect(Collectors.toMap(DoctorArticleNotificationPatient::getPatientId, doctorArticleNotificationPatient -> doctorArticleNotificationPatient));
        List<DoctorArticlePatientVO> list = new ArrayList<>();
        doctorPatientList.forEach(doctorPatient -> {
            DoctorArticleNotificationPatient doctorArticleNotificationPatient = doctorArticleNotificationPatientMap.get(doctorPatient.getPatientId());
            DoctorArticlePatientVO doctorArticlePatientVO = new DoctorArticlePatientVO();
            doctorArticlePatientVO.setId(doctorPatient.getId());
            doctorArticlePatientVO.setName(doctorArticlePatientVO.getName());
            doctorArticlePatientVO.setSelected(doctorArticleNotificationPatient == null ? 0 : 1);
            list.add(doctorArticlePatientVO);
        });
        return list;
    }
}
